package com.shijie.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Submit implements Serializable {

    private Long submitId;

    private Long userId;

    private Long poolId;

    private Status status;

    private String code;

    private CodeType codeType;

    private Integer useMilTime; // ms

    private Integer useKbMemory; // kb

    private String errorMsg;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime putTime;


    public enum Status implements Serializable {

        Commited("commited"), // 已提交

        Compiling("compiling"), // 编译中

        Succeeded("succeeded"), // 成功

        Failed("failed"); // 失败

        private final String value;

        private Status(String value) {
            this.value = value;
        }

        // 指定序列化时的方式
        @JsonValue
        public String getValue() {
            return this.value;
        }

        // 指定反序列化时的方式
        @JsonCreator
        public static Status ofValue(String value) {
            for (Status status : Status.values())
                if (status.getValue().equalsIgnoreCase(value))
                    return status;
            throw new IllegalArgumentException("Submit.Status 未知参数-没有该参数枚举: " + value);
        }

    }


    public enum CodeType implements Serializable {

        Java("Java"),

        JavaScript("JavaScript"),

        C("C"),

        Cpp("Cpp");

        private final String value;

        private CodeType(String value) {
            this.value = value;
        }

        @JsonValue // 序列化时使用
        public String getValue() {
            return this.value;
        }

        @JsonCreator // 反序列化时使用
        public static CodeType ofValue(String value) {
            for (CodeType code : CodeType.values())
                if (code.getValue().equalsIgnoreCase(value))
                    return code;

            throw new IllegalArgumentException("Submit.CodeType 未知参数-没有该参数枚举: " + value);
        }

    }

}
